subroutine init_random_seed(lunit,np,rank)
  use global_param,only:user_seed
  implicit none

  integer,intent(in) :: lunit,np,rank
  integer :: i,n,clock
  integer,dimension(:),allocatable :: seed

  call random_seed(size=n)
  allocate(seed(n))

  call system_clock(count=clock)

  if (user_seed.lt.0) then
     seed=clock+37* (/ (i-1,i=1,n) /)
  else
     seed=(np*rank**2+user_seed)* (/ (i,i=1,n) /)
  end if

  call random_seed(put=seed)

  deallocate(seed)

end subroutine init_random_seed
